package org.raphaello.core.jobs;

import org.raphaello.Prototype.Raphaello;
import org.raphaello.core.Primitive;
import org.raphaello.core.jobs.Job;

import android.util.Log;

public class PropertyChanger extends Job {
	
	private static final String TAG = "PropertyChanger";
	
	public PropertyChanger(String id){
		super(id);
		
		declareProperty("primitive_name", "Primitive");
		declareProperty("property_name", "PropertyName");
		declareProperty("property_value", "PropertyValue");
	}

	@Override
	public void work() {
		String primitiveId = (String)getProperty("primitive_name");
		if(Raphaello.mPrimitives.containsKey(primitiveId)){
			Primitive primitive = Raphaello.mPrimitives.get(primitiveId);
			primitive.fillProperty((String)getProperty("property_name"), 
								  (String)getProperty("property_value"));
			
			// Redraw if the target primitive is a visible object
			if(Raphaello.mObjects.containsKey(primitiveId))
				Raphaello.getView().transition(primitiveId + ".painting");
			
		}
		else{
			Log.e(TAG, "Primitive " + primitiveId + " does not exist");
		}
	}
	
	/* Helper methods for properties */
	
	public final String getPrimitiveName() {
		return (String)getProperty("primitive_name");
	}
	
	public final String getPropertyName() {
		return (String)getProperty("property_name");
	}
	
	public final String getPropertyValue() {
		return (String)getProperty("property_value");
	}
}
